from django.db import models

# Create your models here.

class UserInfo(models.Model):
    name = models.CharField(max_length=32)
    password = models.CharField(max_length=64)
    age = models.IntegerField()
    account = models.DecimalField(max_digits=10, decimal_places=2)
    create_time = models.DateTimeField()
    # 约束
    # 级联删除
    depart = models.ForeignKey(to="Department", to_field="id",on_delete=models.CASCADE)
    # 置空
    # depart = models.ForeignKey(to="Department", to_field="id",null=True,blank=True,on_delete=models.SET_NULL)

    # django中约束
    gender_choice =(
        (1,"男"),
        (2,"女")
    )
    gender = models.SmallIntegerField(choices=gender_choice)
    class Meta:
        db_table = 'django01_userinfo'
        app_label = 'django02'

class Department(models.Model):
    title = models.CharField(max_length=32)
    class Meta:
        db_table = 'django01_department'
        app_label = 'django02'

    def __str__(self):
        return self.title

class Roles(models.Model):
    caption = models.CharField(max_length=32)
    class Meta:
        db_table = 'django01_roles'
        app_label = 'django02'


class BettyNumbers(models.Model):
    mobile = models.CharField(max_length=11)
    price = models.DecimalField(max_digits=10, decimal_places=2)
    level_choice= (
        (1,'一级'),
        (2,'二级'),
        (3,'三级'),
        (4,'四级'),
    )
    level = models.SmallIntegerField(choices=level_choice,default=1)
    status_choice =(
        (1,'已占用'),
        (2,'未使用'),
    )
    status = models.SmallIntegerField(choices=status_choice,default=2)
    class Meta:
        db_table = 'django01_bettynumbers'
        app_label = 'django02'

class Test(models.Model):
    name = models.CharField(max_length=32)
    class Meta:
        db_table = 'django01_test'
        app_label = 'django02'